package com.miaodiyun.httpApiDemo;

import java.net.URLEncoder;
import java.util.Random;

import com.miaodiyun.httpApiDemo.common.Config;
import com.miaodiyun.httpApiDemo.common.HttpUtil;

/**
 * 验证码通知短信接口
 * 
 * @ClassName: IndustrySMS
 * @Description: 验证码通知短信接口
 *
 */
public class IndustrySMS
{
	private static String operation = "/industrySMS/sendSMS";

	private static String accountSid = Config.ACCOUNT_SID;
	private static int ran;
	//	private static String to = "15620238057";
	//private static String smsContent = "【蓝桥科技】登录验证码："+execute()+"，如非本人操作，请忽略此短信。";

	/**
	 * 验证码通知短信
	 */
	public static int execute(String tel)
	{
		String tmpSmsContent = null;
	    try{
	    	ran=random();
	      tmpSmsContent = URLEncoder.encode( "【蓝桥科技】登录验证码："+ran+"，如非本人操作，请忽略此短信。", "UTF-8");
	    }catch(Exception e){
	      
	    }
	    String url = Config.BASE_URL + operation;
	    String body = "accountSid=" + accountSid + "&to=" +tel + "&smsContent=" + tmpSmsContent
	        + HttpUtil.createCommonParam();

	    // 提交请求
	    String result = HttpUtil.post(url, body);
	    System.out.println("result:" + System.lineSeparator() + result);
	    return ran;
	}
	
	//自定义短信随机数生成的方法
	public static int random() {
		
		/*Random rd1 = new Random();
		// 生成随机整数
		int rd2=rd1.nextInt();*/
		int rd2 = (int)((Math.random()*9+1)*100000);
		return rd2;
	}
}
